﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RipPoll.DataAccess;
using RipPoll.Library;

namespace RipPoll.Business
{
    public class ChoiceBO
    {
        public void InsertChoices(List<ChoicePE> choices)
        {
            RippollEntities re = new RippollEntities();

            IQueryable<int> v = from ch in re.Choices
                                select ch.ChoiceGroupId;

            int groupId = 0;
            if (v.Any())
                groupId = v.Max();
            
            groupId++;

            foreach (ChoicePE cp in choices)
            {
                cp.ChoiceGroupId = (int)groupId;
                Choice c = new Choice() { ChoiceGroupId= (int)groupId, ChoiceName = cp.Choice, DateAdded = cp.DateAdded };
                re.AddToChoices(c);
                re.SaveChanges();
                cp.Id = c.Id;
            }
        }
    }
}
